//
//  RJStatusTableCellStatus.m
//  AirQuality
//
//  Created by Po on 15/6/18.
//  Copyright (c) 2015年 Po. All rights reserved.
//

#import "RJStatusTableCellStatus.h"

@interface RJStatusTableCellStatus ()

@property (retain, nonatomic) UILabel * textLabel;
@property (retain, nonatomic) UIImageView * sendImage;
@property (retain, nonatomic) UIImageView * checkImage;
@property (strong, nonatomic) NSString * statusStr;

@end

@implementation RJStatusTableCellStatus

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initInterface];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initInterface];
    }
    return self;
}

- (void)initInterface{
    [self getTextLabel];
   
    [self addSubview:[self getTextLabel]];
   
    [self setBackgroundColor:[UIColor clearColor]];
    [self setHidden:YES];
}
- (void)setStuateText:(NSString *)text
{
    [self setHidden:NO];
    
    NSRange stuatePosition = [text rangeOfString:@"["];
    NSString * stuateText = [text substringFromIndex:stuatePosition.location];
    NSString * stationType = [text substringToIndex:stuatePosition.location];
    if ([stationType isEqualToString:@"直管站"]) {
        ;
    }
    _statusStr = stuateText;

        [self getSendImage];
        [self getCheckImage];
        [self addSubview:[self getSendImage]];
        [self addSubview:[self getCheckImage]];

    [[self getTextLabel] setText:stationType];
    dispatch_queue_t concurrentQueue = dispatch_queue_create("my.statusCell.queue", DISPATCH_QUEUE_CONCURRENT);
    dispatch_async(concurrentQueue, ^{
        dispatch_async(dispatch_get_main_queue(), ^{
//            if ([stuateText isEqualToString:@"[未下发]"]) {
//                [[self getSendImage] setImage:[UIImage imageNamed:@"noSendStuate"]];
//                [[self getCheckImage] setImage:[UIImage imageNamed:@"noCheckStuate"]];
//            } else if ([stuateText isEqualToString:@"[已下发]"]) {
//                [[self getSendImage] setImage:[UIImage imageNamed:@"isSendStuate"]];
//                [[self getCheckImage] setImage:[UIImage imageNamed:@"noCheckStuate"]];
//            } else if ([stuateText isEqualToString:@"[未审核]"]) {
//                [[self getSendImage] setImage:[UIImage imageNamed:@"isSendStuate"]];
//                [[self getCheckImage] setImage:[UIImage imageNamed:@"noCheckStuate"]];
//            } else if ([stuateText isEqualToString:@"[审核完成]"]) {
//                [[self getSendImage] setImage:[UIImage imageNamed:@"isSendStuate"]];
//                [[self getCheckImage] setImage:[UIImage imageNamed:@"isCheckStuate"]];
//            } else if ([stuateText isEqualToString:@"[已完成]"]){
//               [[self getSendImage] setImage:[UIImage imageNamed:@"isSendStuate"]];
//                [[self getSendImage] setImage:[UIImage imageNamed:@"isSendStuate"]];
//            }
//            else if ([stuateText isEqualToString:@"[未完成]"]){
//                [[self getSendImage] setImage:[UIImage imageNamed:@"isSendStuate"]];
//                [[self getCheckImage] setImage:[UIImage imageNamed:@"noCheckStuate"]];
//            }
        });
    });
}

- (UILabel *)getTextLabel{
    if (!_textLabel) {
        CGRect rect = self.frame;
        _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, rect.size.width - rect.size.height * 2, rect.size.height)];
        [_textLabel setFont:[UIFont systemFontOfSize:self.frame.size.height - 4]];
        [_textLabel setTextColor:[UIColor blackColor]];
    }
    return _textLabel;
}

- (UIImageView *)getSendImage {
    if (!_sendImage) {
        CGRect rect = self.frame;
        _sendImage = [[UIImageView alloc] initWithFrame:CGRectMake(rect.size.width - rect.size.height * 2 + 2, 2, rect.size.height-6, rect.size.height-6)];
     NSString * string = [_statusStr isEqualToString:@"[已完成]"] ?@"isSendStuate":@"noSendStuate";
        [_sendImage setImage:[UIImage imageNamed:string]];
    }
    return _sendImage;
}

- (UIImageView *)getCheckImage {
    if (!_checkImage) {
        CGRect rect = self.frame;
        _checkImage = [[UIImageView alloc] initWithFrame:CGRectMake(rect.size.width - rect.size.height + 2, 2, rect.size.height - 6, rect.size.height - 6)];
         NSString * string = [_statusStr isEqualToString:@"[已完成]"] ?@"isCheckStuate":@"noCheckStuate";
        [_checkImage setImage:[UIImage imageNamed:string]];
    }
    return _checkImage;
}

@end
